package fenzhixianjie.onClass.exer01;

import java.util.Scanner;

public class Main {
    private static boolean canExpand = false;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int n = sc.nextInt();
            int[][] mat = new int[n][n];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    mat[i][j] = sc.nextInt();
                }
            }
            int[][] nextPos = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
            for (int i = 1; i < n - 1; i++) {
                for (int j = 1; j < n - 1; j++) {
                    canExpand = false;
                    if (mat[i][j] == 0) {
                        boolean[][] flag = new boolean[n][n];
                        dfs(i, j, nextPos, n, n, flag, mat);
                        if (!canExpand) {
                            mat[i][j] = 2;
                        }
                    }
                }
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    System.out.print(mat[i][j] + " ");
                }
                System.out.println();
            }
        }
    }

    public static void dfs(int curRow, int curCol, int[][] nextPos, int rows, int cols, boolean[][] flag, int[][] mat) {
        flag[curRow][curCol] = true;
        if (curRow == 0 || curRow == rows - 1 || curCol == 0 || curCol == cols - 1) {
            canExpand = true;
            return;
        }
        for (int i = 0; i < 4; i++) {
            int nextRow = curRow + nextPos[i][0];
            int nextCol = curCol + nextPos[i][1];
            if (nextRow >= 0 && nextRow < rows && nextCol >= 0 && nextCol < cols && mat[nextRow][nextCol] == 0 && !flag[nextRow][nextCol]) {
                dfs(nextRow, nextCol, nextPos, rows, cols, flag, mat);
            }
        }
    }
}
